export default {
  data() {
    return {
      is_apply:false,
      is_identity:false,
      show_page:false,
      minDate: new Date(1900, 0, 1),
      maxDate: new Date(2055, 10, 1),
      goodResult: [],
      radio: 0,
      radio_enterprise: 0,
      columns: ["男", "女"],
      columnsOffice: [],
      columnsGood: [],
      agremment: false,
      //开关-start
      showGender: false,
      agreementShow: false,
      showOffice: false,
      showEnterprise: false,
      showGood: false,
      jobShow: false,
      streetShow: false,
      addressShow: false,
      strShow: false,
      status: "0",
      //开关-end
      district: district,
      street: "", //街道
      addressName: "", //地区
      currentDate: new Date(),
      info: {
        name: "",
        logo: "",
        logo_img: "",
        gender: "",
        office: "",
        lf_id: "",
        mobile: "",
        job_year: "",
        job_name: "",
        job_no: "",
        Practice: "",
        Practice_img: "",
        job_time: "",
        identity_card_front: "",
        identity_card_front_img: "",
        identity_card_backend: "",
        identity_card_backend_img: "",
        desc: "",
        addressName: "",
        street: "",
        locationTitle: "", //地址名
        detailed_address: "",
        currentGood: []
      },
      province_id: 0, //省id
      city_id: 0, //市id
      district_id: 0, //区id
      street_id: 0, //街道id
      form: {
        //省市区
        province: "",
        city: "",
        district: ""
      },
      point: 0, //经纬度
      districtVal: "",
      certification: "", //资质图片
      upload_photo: {
        //文件上传图片
        Practice: [],
        identity_card_front: [],
        identity_card_backend: [],
        logo: []
      },
      genderImg: {
        man: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/debt/manNo.png",
        women: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/debt/womenNo.png"
      },
      route_name: "",
      apply_for_type: "",
      isLoadMore: true,
      current_page: 1,
      last_page: 1,
      paransInfo: {
        l_content: "",
        l_status: "",
        l_top_thumb_image: ""
      },
      lawyerId: "",
      search_lawyer_firm:"",
      //企业列表
      enterprise_name: "",
      current_page_enterprise: 1,
      last_page_enterprise: 1,
      columnsEnterprise: []
    };
  },
  activated() {
    this.apply_for_type = this.$route.query.apply_for;
    if (!window.localStorage.getItem("province") || !window.localStorage.getItem("city") || !window.localStorage.getItem("district")) {
      this.getAddressInfo();
    }
    this.getCtegory();
    if(this.apply_for_type!=='lawYerManagement'){
      this.getLawyerOffice();
    }
    if(this.apply_for_type == 'lawyerDetail' || this.apply_for_type == 'officeDetail'){
      this.show_page = true;
    }
    if (this.$route.query.share || this.apply_for_type == "lawYerManagement" || this.apply_for_type == "lawOffice") {
      this.check_apply();
    }
    if (this.apply_for_type == "lawOffice") {
      this.getEnterprise();
    }
    this.ready();
    this.apply_for_type = this.$route.query.apply_for;
    if (this.apply_for_type == "lawYerManagement" || this.apply_for_type == "lawOffice") {
      if (JSON.stringify(this.$route.params) == "{}" && JSON.parse(localStorage.getItem("lawyerInfo")) == null) {
        this.getApplyForInfo();
        return;
      }
      if (JSON.stringify(this.$route.params) == "{}") {
        this.paransInfo = JSON.parse(localStorage.getItem("lawyerInfo"));
      } else {
        this.paransInfo.l_content = this.$route.params.l_content;
        this.paransInfo.l_status = this.$route.params.l_status;
        this.paransInfo.l_top_thumb_image = this.$route.params.l_top_thumb_image;
      }
      localStorage.setItem("lawyerInfo", JSON.stringify(this.paransInfo));
    }
  },
  deactivated() {
    localStorage.removeItem("lawyerInfo");
    if (this.$refs.lawyerOffice) {
      this.$refs.lawyerOffice.removeEventListener("scroll", this.gethandleScroll);
    }
    if (this.$refs.enterprise) {
      this.$refs.enterprise.removeEventListener("scroll", this.handleScrollEnterprise);
    }
  },
  watch: {
    search_lawyer_firm(v){
      if(this.timer) clearTimeout(this.timer);
      this.timer = setTimeout(()=>{
         this.getLawyerOffice(v)
      },500)
    },
    $route(to, form) {
      if (form.name == "lawyerPlatformApplyFor" && to.name == "lawyerPlatform") {
        this.init();
      }
    },
    showOffice(v) {
      if (v) {
        this.$nextTick(() => {
          let el = this.$refs.lawyerOffice;
          el.addEventListener("scroll", this.gethandleScroll);
        });
      }
    },
    showEnterprise(v) {
      if(v){
        this.$nextTick(() => {
          let el = this.$refs.enterprise;
          el.addEventListener("scroll", this.handleScrollEnterprise);
        });

      }
    }
  },
  methods: {
    handleScrollEnterprise() {
      let el = this.$refs.enterprise,
        scrollTop = el.scrollTop,
        clientHeight = el.clientHeight,
        scrollHeight = el.scrollHeight;
      if (scrollTop + clientHeight + 105 > scrollHeight) {
        if (this.isLoadMore) {
          console.log(this.current_page_enterprise);
          console.log(this.last_page_enterprise);
          if (this.current_page_enterprise >= this.last_page_enterprise) {
            return false;
          }
          this.isLoadMore = false;
          this.getMoreEnterpriseData();
        }
      }
    },
    getMoreEnterpriseData(){
      let page = this.current_page_enterprise+1;
      $http.post("plugin.lawyer-platform.frontend.controllers.lawyer-firm.verify",{page}).then(res => {
        this.isLoadMore = true;
        let data = res.data.business_list.data;
        if (res.result == 1 && data.length !== 0) {
            this.columnsEnterprise = this.columnsEnterprise.concat(data);
            this.current_page_enterprise = res.data.business_list.current_page;
            this.last_page_enterprise = res.data.business_list.last_page;

        }
      });
    },
    //企业列表
    getEnterprise() {
      $http.post("plugin.lawyer-platform.frontend.controllers.lawyer-firm.verify").then(res => {
        let data = res.data.business_list.data;
        if (res.result == 1 && data.length !== 0) {
          if (data.length == 1) {
            this.radio_enterprise = data[0].id;
          } else {
            this.columnsEnterprise = data;
            this.last_page_enterprise = res.data.business_list.last_page;
          }
        }
      });
    },
    //获取地址信息
    getAddressInfo() {
      //saveAddresssInfo
      $http
        .get("member.member-address.address", {
          i: this.fun.getKeyByI(),
          type: this.fun.getTyep()
        })
        .then(
          response => {
            if (response.result == 1) {
              var province = JSON.stringify(response.data.province);
              var city = JSON.stringify(response.data.city);
              var district = JSON.stringify(response.data.district);
              localStorage.setItem("province", province);
              localStorage.setItem("city", city);
              localStorage.setItem("district", district);
            }
          },
          function(response) {
            // error callback
          }
        );
    },
    getApplyForInfo() {
      $http.get("plugin.lawyer-platform.frontend.controllers.index.index").then(res => {
        if (res.result == 1) {
          if (this.$route.query.apply_for == "lawOffice") {
            this.paransInfo.l_top_thumb_image = res.data.set ?res.data.set.lf_top_thumb_image : '';
          } else {
            this.paransInfo.l_top_thumb_image = res.data.set ?res.data.set.l_top_thumb_image : '';
          }
          this.paransInfo.l_content = res.data.set? res.data.set.l_content :"";
          this.paransInfo.l_status = res.data.set?res.data.set.l_status : "";
          this.diy_name = res.data.set ? res.data.set.diy_name : "律师平台";
          this.fun.setWXTitle(this.diy_name);
        }
      });
    },
    //是否已申请过律所、律师
    check_apply() {
      let url = "";
      if (this.$route.query.apply_for == "lawOffice") {
        url = "plugin.lawyer-platform.frontend.controllers.lawyer-firm.verify";
      } else {
        url = "plugin.lawyer-platform.frontend.controllers.lawyer.verify";
      }
      $http.get(url).then(res => {
        if (res.result == 1) {
          // this.$toast(res.msg);
          if (this.$route.query.share) {
            this.$router.push(this.fun.getUrl("lawyerPlatform"));
          } else {
            this.is_apply = res.data.is_apply;
            this.is_identity = res.data.is_identity;
            if(res.data.is_apply && res.data.is_identity){
              this.$router.push(this.fun.getUrl("lawOffice"));
              return;
            }
            this.show_page = true;
          }
        }
      });
    },
    //律师详情
    getLawyerDetail() {
      $http.get("plugin.lawyer-platform.frontend.controllers.lawyer.getDetail").then(res => {
        if (res.result == 1) {
          this.upload_photo.logo = [];
          this.upload_photo.identity_card_front = [];
          this.upload_photo.identity_card_backend = [];
          this.upload_photo.Practice = [];
          let data = res.data.detail,
            _resName = this.columnsOffice.filter(item => item.id == data.lf_id);

          let date = new Date(Number(data.start_time));
          let year = date.getFullYear(),
            month = date.getMonth() + 1,
            day = date.getDate();
          if (day < 10) {
            day = `0${day}`;
          }
          if (month < 10) {
            month = `0${month}`;
          }

          this.info.job_time = `${year}-${month}-${day}`;
          this.lawyerId = data.id;
          this.info.name = data.name;
          this.info.logo_img = data.avatar;
          this.info.gender = data.gender == "1" ? "男" : "女";
          this.info.mobile = data.tel;
          this.info.office = _resName[0].name;
          this.info.job_year = data.year;
          this.info.job_name = data.title;
          this.info.job_no = data.number;
          this.info.desc = data.introduction;
          this.info.Practice_img = data.number_thumb;
          this.info.identity_card_backend_img = data.id_card_back_thumb;
          this.info.identity_card_front_img = data.id_card_front_thumb;
          this.upload_photo.logo.push({ url: data.avatar_image });
          this.upload_photo.identity_card_front.push({ url: data.id_card_front_thumb_image });
          this.upload_photo.identity_card_backend.push({ url: data.id_card_back_thumb_image });
          this.upload_photo.Practice.push({ url: data.number_thumb_image });
          this.radio = data.lf_id;
          this.info.locationTitle = data.location_name;
          this.info.currentGood = data.category_data||[];
          this.info.currentGood.forEach(item => (item.status = true));
          this.province_id = data.address.province; //省id
          this.city_id = data.address.city; //市id
          this.district_id = data.address.area; //区id
          this.info.addressName = data.show_address;
        }
      });
    },
    //律所详情
    getOfficeDetail() {
      $http.get("plugin.lawyer-platform.frontend.controllers.lawyer-firm.getDetail").then(res => {
        if (res.result == 1) {
          this.$nextTick(() => {
            let data = res.data.detail;
            this.officeId = data.id;
            this.info.name = data.name;
            this.info.desc = data.introduction;
            this.info.logo_img = data.logo;
            this.info.Practice_img = data.thumb;
            this.info.mobile = data.tel;
            this.status = data.status;
            this.info.detailed_address = data.address_detail;
            this.upload_photo.Practice = [];
            this.upload_photo.logo = [];
            this.upload_photo.Practice.push({ url: data.thumb_image });
            this.upload_photo.logo.push({ url: data.logo_image });
            this.province_id = data.address.province; //省id
            this.city_id = data.address.city; //市id
            this.district_id = data.address.area; //区id
            if (data.street_id) {
              this.street_id = data.address.street; //街道id
              this.getStreet();
            }
            let province = JSON.parse(localStorage.getItem("province")),
              city = JSON.parse(localStorage.getItem("city")),
              area = JSON.parse(localStorage.getItem("district")),
              provinceName = province.filter(item => item.id == data.address.province),
              cityName = city.filter(item => item.id == data.address.city),
              districtName = area.filter(item => item.id == data.address.area);
            this.info.addressName = provinceName[0].areaname + cityName[0].areaname + districtName[0].areaname;
          });
        }
      });
    },
    gethandleScroll() {
      let el = this.$refs.lawyerOffice,
        scrollTop = el.scrollTop,
        clientHeight = el.clientHeight,
        scrollHeight = el.scrollHeight;
      if (scrollTop + clientHeight + 105 > scrollHeight) {
        if (this.isLoadMore) {
          if (this.current_page >= this.last_page) {
            return false;
          }
          this.getMoreData();
        }
      }
    },
    getMoreData() {
      this.isLoadMore = false;
      let page = this.current_page + 1;
      $http.get("plugin.lawyer-platform.frontend.controllers.lawyer.getLawyerFirm", { page }).then(res => {
        this.isLoadMore = true;
        if (res.result == 1) {
          this.columnsOffice = this.columnsOffice.concat(res.data.list.data);
          this.current_page = res.data.list.current_page;
          this.last_page = res.data.list.last_page;
        }
      });
    },
    //获取律所列表
    getLawyerOffice(name="") {
      $http.get("plugin.lawyer-platform.frontend.controllers.lawyer.getLawyerFirm",{name}).then(res => {
        if (res.result == 1) {
          this.columnsOffice = res.data.list.data;
          this.current_page = res.data.list.current_page;
          this.last_page = res.data.list.last_page;
          if (this.apply_for_type == "officeDetail") {
            this.getOfficeDetail();
          }
          if (this.apply_for_type == "lawyerDetail") {
            this.getLawyerDetail();
          }
        }
      });
    },
    getCtegory() {
      $http.get("plugin.lawyer-platform.frontend.controllers.lawyer.getCategory").then(res => {
        if (res.result == 1) {
          this.columnsGood = res.data.category||[];
          this.columnsGood.forEach(item => (item.status = false));
        }
      });
    },
    init() {
      this.info.currentGood = [];
      this.upload_photo.Practice = [];
      this.upload_photo.identity_card_front = [];
      this.upload_photo.identity_card_backend = [];
      this.upload_photo.logo = [];
      this.columnsGood = [];
      this.officeId = "";
      this.agremment = false;
      this.info.locationTitle = "";
      this.upload_photo = {
        //文件上传图片
        Practice: [],
        identity_card_front: [],
        identity_card_backend: [],
        logo: []
      };
      this.info = {
        name: "",
        logo: "",
        gender: "",
        office: "",
        mobile: "",
        job_year: "",
        job_name: "",
        job_no: "",
        Practice: "",
        job_time: "",
        identity_card_front: "",
        identity_card_backend: "",
        desc: "",
        addressName: "",
        street: "",
        locationTitle: "", //地址名
        detailed_address: "",
        currentGood: []
      };
    },
    toggleGender(sex) {
      if (sex == "man") {
        this.genderImg.man = "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/debt/manYes.png";
        this.genderImg.women = "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/debt/womenNo.png";
      } else {
        this.genderImg.man = "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/debt/manNo.png";
        this.genderImg.women = "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/debt/womenYes.png";
      }
      this.info.gender = sex == "man" ? "男" : "女";
      this.showGender = false;
    },
    ready() {
      this.fun
        .getLocation()
        .then(res => {
          this.point = res.point;
          this.info.locationTitle = res.title;
        })
        .catch(err => {
          console.log(err);
        });
    },
    confirmOffice() {
      // let _arr = this.columnsOffice.filter(item => {
      //   if (item.id == this.radio) {
      //     return item.name;
      //   }
      // });
      if(!this.columnsOffice) return this.showOffice = false;
      let _arr = this.columnsOffice.filter(item => item.id == this.radio);
      this.info.office = _arr[0].name;
      this.showOffice = false;
    },
    closeEnterprise(){
      if(this.enterprise_name == ''){
        this.radio_enterprise =''
      }
      this.showEnterprise = false;
    },
    confirmEnterprise() {
      if(!this.columnsEnterprise) return this.showEnterprise = false;
      if(this.radio_enterprise){
        let _arr = this.columnsEnterprise.filter(item => item.id == this.radio_enterprise);
        this.enterprise_name = _arr[0].name;
      }


      this.showEnterprise = false;
    },
    confirmJobTime(value) {
      let date = new Date(value);
      let year = date.getFullYear(),
        month = date.getMonth() + 1,
        day = date.getDate();
      if (day < 10) {
        day = `0${day}`;
      }
      if (month < 10) {
        month = `0${month}`;
      }

      this.info.job_time = `${year}-${month}-${day}`;
      this.jobShow = false;
    },
    //定位
    toGeolocation() {
      this.$store.commit("setReferer", window.location.href);
      this.$router.push(this.fun.getUrl("o2oLocation_loc", { fromHome: 1 }));
    },
    // 身份证正面
    onRead_front(e) {
      this.uploadPhoto(e, "identity_card_front");
    },
    // 身份证反面
    onRead_backend(e) {
      this.uploadPhoto(e, "identity_card_backend");
    },
    onRead_practice(e) {
      this.uploadPhoto(e, "Practice");
    },
    onRead_logo(e) {
      this.uploadPhoto(e, "logo");
    },
    uploadPhoto(e, type) {
      let fd = new FormData();
      fd.append("file", e.file);
      this.upload_photo[type][0].status = "uploading";
      this.upload_photo[type][0].message = "上传中...";
      axios.post(this.fun.getRealUrl("upload.uploadPic"), fd, { headers: { "Content-Type": "multipart/form-data" } }).then(res => {
        if (res.data.result == 1) {
          let img = res.data.data.img;
          this.$toast(res.data.msg);
          this.upload_photo[type][0].status = "done";
          this.upload_photo[type][0].url = res.data.data.img_url;
          this.info[type] = res.data.data.img_url;
          if (type == "identity_card_front") {
            this.info.identity_card_front_img = img;
          } else if (type == "identity_card_backend") {
            this.info.identity_card_backend_img = img;
          } else if (type == "Practice") {
            this.info.Practice_img = img;
          } else {
            this.info.logo_img = img;
          }
        } else {
          this.upload_photo[type][0].message = "failed";
          this.$toast(res.data.msg);
        }
      });
    },
    closeGood(data) {
      let index = this.info.currentGood.findIndex(item => item.id == data.id);
      this.info.currentGood.splice(index, 1);
    },
    confirmGood(flag) {
      let _arr = JSON.parse(JSON.stringify(this.info.currentGood));
      let newArr = null;
      if (flag == "open" && this.columnsGood.length > 0) {
        newArr = _arr.map(item => item.name);
        this.columnsGood.forEach(item => {
          if (!newArr.includes(item.name)) {
            item.status = false;
          }
        });
        this.showGood = true;
      } else if (flag == "cancel") {
        this.info.currentGood = _arr;
        this.showGood = false;
      } else {
        this.info.currentGood = this.columnsGood.filter(item => item.status == true);
        this.showGood = false;
      }
    },
    chooseGood(i) {
      let status = this.columnsGood[i].status;
      this.$set(this.columnsGood, i, { status: !status, title: this.columnsGood[i].title, id: this.columnsGood[i].id });
    },
    onConfirmGender(value) {
      this.info.gender = value;
      this.showGender = false;
    },
    onConfirmOffice(value) {
      this.info.office = value.name;
      this.info.lf_id = value.id;
      this.showOffice = false;
    },
    submit() {
      if (this.apply_for_type == "lawYerManagement" || this.apply_for_type == "lawyerDetail") {
        this.apply_for_lawyer();
      }
      if (this.apply_for_type == "lawOffice" || this.apply_for_type == "officeDetail") {
        this.apply_for_lawOffice();
      }
    },
    //律所申请
    apply_for_lawOffice() {
      let json = {
        name: "请输入律所名称",
        logo_img: "请上传logo",
        mobile: "请输入联系电话",
        desc: "请输入简介",
        Practice_img: "请上传资质",
        addressName: "请选择律所所在地址",
        detailed_address: "请输入详细地址",
        status: "请选择状态"
      };

      let form = {
        name: this.info.name,
        logo: this.info.logo_img,
        tel: this.info.mobile,
        thumb: this.info.Practice_img,
        introduction: this.info.desc,
        address: {
          area: this.district_id,
          city: this.city_id,
          province: this.province_id
        },
        address_detail: this.info.detailed_address,
        status: this.status
      };
      if (this.strShow) {
        json.street = "请选择街道";
        form.address.street = this.street_id;
      }
      for (let key in json) {
        if (this.info[key] == "") {
          return this.$toast(json[key]);
        }
      }
      if (!this.agremment && this.apply_for_type == "lawOffice" && this.paransInfo.l_status==1) {
        return this.$toast("请勾选阅读并同意协议");
      }
      let dataForm = {
        form
      };
      if (this.apply_for_type == "officeDetail") {
        dataForm.id = this.officeId;
      }
      if (this.apply_for_type == "lawOffice") {
        dataForm.form.business_id = this.radio_enterprise;
      }

      if (this.$route.query.share) {
        dataForm.form.merchant_member_id = this.$route.query.merchant_member_id;
      }
      let url = this.apply_for_type == "lawOffice" ? "plugin.lawyer-platform.frontend.controllers.lawyer-firm.apply" : "plugin.lawyer-platform.frontend.controllers.lawyer-firm.edit";
      $http.post(url, dataForm).then(res => {
        if (res.result == 1) {
          this.$toast(res.msg);
          if (this.apply_for_type == "officeDetail") {
            this.$router.go(-1);
          } else {
            this.$router.push(this.fun.getUrl("lawyerPlatform"));
          }
        } else {
          this.$toast(res.msg);
        }
      });
    },
    // 律师申请
    apply_for_lawyer() {
      let json = {
        name: "请输入姓名",
        logo_img: "请上传头像",
        gender: "请选择性别",
        mobile: "请输入手机号",
        office: "请选择所属律所",
        currentGood: "请选择擅长领域",
        job_year: "请输入执业年限",
        job_name: "请输入职称",
        job_no: "请输入执业证号",
        Practice_img: "请上传执业证照片",
        job_time: "请选择执业起始时间",
        desc: "请输入简介",
        addressName: "请选择服务区域",
        locationTitle: "请选择地理位置"
      };
      for (let key in json) {
        if (this.info[key] == "") {
          return this.$toast(json[key]);
        }
      }
      if (!this.agremment && this.apply_for_type == "lawYerManagement") {
        return this.$toast("请勾选阅读并同意协议");
      }
      let category_ids = this.info.currentGood.map(item => {
        if (item.status) {
          return item.id;
        }
      });
      let start_time = this.info.job_time.replace(/-/g, ",");
      start_time = new Date(start_time).getTime() / 1000;
      let form = {
        name: this.info.name,
        avatar: this.info.logo_img,
        gender: this.info.gender == "男" ? 1 : 2,
        tel: this.info.mobile,
        lf_id: this.radio,
        category_ids,
        year: this.info.job_year,
        title: this.info.job_name,
        number: this.info.job_no,
        number_thumb: this.info.Practice_img,
        id_card_front_thumb: this.info.identity_card_front_img,
        id_card_back_thumb: this.info.identity_card_backend_img,
        start_time,
        introduction: this.info.desc,
        address: {
          area: this.district_id,
          city: this.city_id,
          province: this.province_id
        },
        location: [this.point.lng, this.point.lat],
        location_name: this.info.locationTitle
      };
      let url = this.apply_for_type == "lawyerDetail" ? "plugin.lawyer-platform.frontend.controllers.lawyer.edit" : "plugin.lawyer-platform.frontend.controllers.lawyer.apply";

      let dataForm = {
        form
      };
      if (this.apply_for_type == "lawyerDetail") {
        dataForm.id = this.lawyerId;
      }
      if (this.$route.query.share) {
        dataForm.form.merchant_member_id = this.$route.query.merchant_member_id;
      }
      $http.post(url, dataForm).then(res => {
        if (res.result == 1) {
          this.$toast(res.msg);
          if (this.apply_for_type == "lawyerDetail") {
            this.$router.push(this.fun.getUrl("lawYerManagement"));
          } else {
            this.$router.push(this.fun.getUrl("lawyerPlatform"));
          }
        } else {
          this.$toast(res.msg);
        }
      });
    },
    back() {
      if (window.history.length <= 1) {
        this.$router.push(this.fun.getUrl("home", {}));
        return;
      }
      this.$router.go(-1);
    },
    openEnterprise() {
      this.showEnterprise = true;
      if (this.radio_enterprise) {
        let arr = this.columnsEnterprise.filter(item => item.name == this.enterprise_name);
        this.radio_enterprise = arr[0].id;
      }
    },
    streetConfirm(item) {
      this.street_id = item.id;
      this.info.street = item.areaname;
      this.streetShow = false;
    },
    streetChoose() {
      if (this.is_region == 1 && this.fun.isTextEmpty(this.info.addressName)) {
        this.$dialog.alert({ message: "请先选择所在地区" });
      } else {
        this.streetShow = true;
      }
    },
    addressCallback(obj) {
      console.log(obj);
      this.info.street = "";
      this.districtVal = "";
      this.info.addressName = obj.itemName1 + " " + obj.itemName2 + " " + obj.itemName3;
      this.form.province = obj.itemName1;
      this.form.city = obj.itemName2;
      this.form.district = obj.itemName3;

      this.province_id = obj.itemValue1;
      this.city_id = obj.itemValue2;
      this.district_id = obj.itemValue3;

      this.getStreet();
    },
    // 获取街道
    getStreet() {
      $http
        .get("member.memberAddress.street", {
          district_id: this.district_id
        })
        .then(response => {
          if (response.result === 1 && !this.fun.isTextEmpty(response.data)) {
            if (this.street_id) {
              response.data.forEach(item => {
                if (item.id == this.street_id) {
                  this.info.street = item.areaname;
                }
              });
            }
            if (!this.fun.isTextEmpty(response.data) && response.data.length > 0) {
              this.districtVal = response.data;
              this.strShow = true;
            } else {
              this.strShow = false;
            }
          } else {
            this.strShow = false;
          }
        })
        .catch(error => {
          this.strShow = false;
          console.log(error);
        });
    }
  }
};
